package com.example.listviewtest

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.listViewTest.R

class CatAdapter(activity: Activity, val resourceId:Int, data: List<Cat>):
    ArrayAdapter<Cat>(activity,resourceId,data) {
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = LayoutInflater.from(context).inflate(resourceId,parent,false)
        val catImage :ImageView = view.findViewById(R.id.catImage)
        val catName : TextView = view.findViewById(R.id.catName)
        val cat = getItem(position)
        if (cat!=null){
            catImage.setImageResource(cat.imageId)
            catName.text = cat.name
        }
        return view
    }
}


